package IPrototipo.Funcionalidades.Menues;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.Border;

import de.javasoft.plaf.synthetica.SyntheticaOrangeMetallicLookAndFeel;

import IPrototipo.Gestores.GestorErrores;



public abstract class iDialogGeneral extends JDialog {

	public Dimension label;
	public Dimension datos;
	public Dimension panel;
	private boolean boton;
	
	private Border redline;
	private Border text;
	private Border combo;
	private Vector<Object> obligatorios;
	
	
	public GestorErrores gError= new GestorErrores();

	private static final long serialVersionUID = 1L;

	public iDialogGeneral(FrameUsuarioAutenticado perteneciente, boolean modal) {
		super(perteneciente,modal);
		Dimension tam=new Dimension(400, 500);
		setPreferredSize(tam);
		//setTamanio(tam);

		
		setFont(new Font("Andalus", Font.PLAIN, 14));

		setText( (new JTextField()).getBorder());
		setCombo((new JComboBox<String>()).getBorder());
		setRedline(BorderFactory.createLineBorder(Color.red));
		
		panel= new Dimension(1000, 40);
		label=new Dimension(80,30);
		datos= new Dimension(120, 30);

	    try 
	    {
	      UIManager.setLookAndFeel(new SyntheticaOrangeMetallicLookAndFeel());
	    } 
	    catch (Exception e) 
	    {
	    	e.printStackTrace();
	    }
		

	/*	
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (Exception e) {
		    //TODO NO SE PUDO PONER EL LOOK AND FEEL
			}
*/
		

	}
	public void setTamanio(Dimension tam){
		setMinimumSize(tam);
		setMaximumSize(tam);
		setPreferredSize(tam);
	}
	
	public void activarDG(){
		setLocationRelativeTo(getParent());
		setVisible(true);
		getParent().setFocusable(false);

	}
	public boolean isBoton() {
		return boton;
	}
	public void setBoton(boolean boton) {
		this.boton = boton;
	}
	public Border getRedline() {
		return redline;
	}
	public void setRedline(Border redline) {
		this.redline = redline;
	}
	public Border getText() {
		return text;
	}
	public void setText(Border text) {
		this.text = text;
	}
	public Border getCombo() {
		return combo;
	}
	public void setCombo(Border combo) {
		this.combo = combo;
	}


	@SuppressWarnings("unchecked")
	// Devuelve true si estan todos completos.
	public boolean camposObligatorios(Vector<Object> componentes){
		boolean flag= true;
		if(!componentes.isEmpty()){
			for(int i=0;i<componentes.size();i++){
				Object elemento=componentes.get(i);
				
				try {
					if(((JTextField) elemento).getText().equals("")){
						((JTextField) elemento).setBorder(redline);
						flag=false;
					}else ((JTextField) elemento).setBorder(text);
					} catch (Exception e) {;}

				try {
					if(((JTextArea) elemento).getText().equals("")){
						((JTextArea)elemento).setBorder(redline);
						flag=false;
					}else ((JTextArea) elemento).setBorder(text);
					} catch (Exception e) {;}

				try {
					if(((JComboBox<String>) elemento).getSelectedItem().equals("")){
						((JComboBox<String>)elemento).setBorder(redline);
						flag=false;
					}else ((JComboBox<String>) elemento).setBorder(combo);
					} catch (Exception e) {;}
				
			}
		}
		return flag;
		
	}
	public Vector<Object> getObligatorios() {
		return obligatorios;
	}
	public void setObligatorios(Vector<Object> obligatorios) {
		this.obligatorios = obligatorios;
	}


	

}
